﻿' Copyright (c) Microsoft Corporation. All rights reserved.
Option Strict Off
Imports System.Xml
Imports SHDocVw
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Text

Public Class BrowserWithoutTabs1
#Region " API "
    'This is the API to get an icon of a favourite
    Private Structure SHFILEINFO
        Public hIcon As IntPtr
        Public iIcon As Integer
        Public dwAttributes As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Public szDislayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szTypeName As String
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
            (ByVal pszPath As String, _
             ByVal dwFileAttributes As Integer, _
             ByRef psfi As SHFILEINFO, _
             ByVal cbFileInfo As Integer, _
             ByVal uFlags As Integer) As IntPtr

    Private Const SHGFI_ICON = &H100
    Private Const SHGFI_SMALLICON = &H1
    Private Const SHGFI_LARGEICON = &H0
    Private nIndex
#End Region

    <DllImport("user32.dll")> _
    Private Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
    End Function

    Dim i As Integer = 0
    'Friend WithEvents tsbWebSite1 As System.Windows.Forms.ToolStripButton

    'Dim xmldoc As New XmlDocument

    'Private Sub GoToUrl(ByVal sWebsite As String)
    'Dim xPath As String = "//WebSite[Name='" & sWebsite & "']/URL"
    'Dim xn As XmlNode = xmldoc.SelectSingleNode(xPath)

    'WebBrowser1.Url = New Uri(xn.InnerText)
    'End Sub

    Private Sub tsbBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbBack.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub tsbForward_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbForward.Click
        WebBrowser1.GoForward()
    End Sub

    Private Sub tsbHome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbHome.Click
        If My.Settings.UseBBrowserHomePage = "True" Then
            WebBrowser1.Navigate(My.Settings.BBrowserHomePageUrl)
        ElseIf My.Settings.UseBBrowserHomePage = "False" Then
            WebBrowser1.GoHome()
        End If
    End Sub

    Private Sub tsbRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbRefresh.Click
        WebBrowser1.Refresh()
    End Sub

    'Private Sub tsbManage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbManage.Click
    'Dim frmManage As New Sites
    'frmManage.ShowDialog()

    'AddToolStripButtons()
    'End Sub

    Private Sub Browser_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If (e.KeyCode = Keys.F1) Then
            AboutBox1.ShowDialog()
        ElseIf (e.KeyCode = Keys.F5) Then
            WebBrowser1.Refresh()
        ElseIf (e.KeyCode = Keys.ControlKey) And (e.KeyCode = Keys.P) Then
            PrintDialog1.ShowDialog()
            WebBrowser1.Print()
        ElseIf (e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.O) Then
            Dim Open As New OpenFileDialog()
            Open.Title = "Open Local Webpage"
            Open.CheckFileExists = True
            Open.Filter = "All Files (*.*)|*.*"
            Open.ShowDialog()
            Try
                WebBrowser1.Navigate(Open.FileName)
            Catch ex As Exception
                'Do nothing on Exception
            End Try
        ElseIf (e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.X) Then
            Me.Close()
        ElseIf (e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.U And e.KeyCode = Keys.C) Then
            My.Computer.Clipboard.Clear()
            My.Computer.Clipboard.SetText(txtUrl.Text)
        ElseIf (e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.W And e.KeyCode = Keys.S) Then
            WebBrowser1.ShowSaveAsDialog()
        End If
    End Sub

    Private Sub frmBrowser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'AddToolStripButtons()
        My.Settings.IsFormOpen = True
        LoadFavourites()
        KeyPreview = True

        If My.Settings.ShowHomePageAtStartUp = "Yes" Then
            If My.Settings.UseBBrowserHomePage = "True" Then
                WebBrowser1.Navigate(My.Settings.BBrowserHomePageUrl)
                My.Settings.IsFormLoading = False
            ElseIf My.Settings.UseBBrowserHomePage = "False" Then
                WebBrowser1.GoHome()
                My.Settings.IsFormLoading = False
            End If
        ElseIf My.Settings.ShowHomePageAtStartUp = "No (Show Blank Page)" Then
            WebBrowser1.Navigate("about:blank")
            My.Settings.IsFormLoading = False
        ElseIf My.Settings.ShowHomePageAtStartUp = "No (Show Google)" Then
            WebBrowser1.Navigate("http://www.google.co.uk")
            My.Settings.IsFormLoading = False
        End If

        My.Settings.TimesLoadUntilNewsReminder -= 1
        My.Settings.Save()

        Timer3.Enabled = True
        Timer3.Start()
    End Sub

    'Private Sub AddTSButton(ByVal buttonName As String, ByVal webSiteName As String)
    'Dim newbutton As New System.Windows.Forms.ToolStripButton

    'newbutton.Name = buttonName
    'newbutton.Text = webSiteName
    'newbutton.DisplayStyle = ToolStripItemDisplayStyle.Text

    'ToolStrip.Items.Add(newbutton)

    'AddHandler newbutton.Click, AddressOf tsbutton_Click

    'End Sub

    'Private Sub AddToolStripButtons()
    ' Load the XML file with user defined Web sites.
    'xmldoc.Load("C:\WebSites.xml")

    ' TEmpty the toolstrip with the user defined Web sites
    'ToolStrip.Items.Clear()

    ' Loop through the XML file and add a toolstrip button for each
    ' user defined Web site.
    'Dim websiteNodes As XmlNodeList
    'Dim webSiteNode As XmlNode
    'websiteNodes = xmldoc.GetElementsByTagName("WebSite")
    'Dim iCount As Integer = 1

    'For Each webSiteNode In websiteNodes
    'Dim eachSiteNodes As XmlNodeList
    'Dim eachSiteNode As XmlNode
    'eachSiteNodes = webSiteNode.ChildNodes

    'For Each eachSiteNode In eachSiteNodes
    'If eachSiteNode.Name = "Name" Then
    'AddTSButton("tsWebsite" & iCount.ToString, eachSiteNode.InnerText)
    'iCount += 1
    'End If
    ' Next
    'Next

    'End Sub

    'Private Sub tsbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    'Dim aButton As ToolStripButton = CType(sender, ToolStripButton)
    'GoToUrl(aButton.Text)
    'End Sub

    Private Sub tsbGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsbGo.Click
        WebBrowser1.Navigate(txtUrl.Text)
        Try
            WebBrowser1.Url = New Uri(txtUrl.Text)
        Catch
        End Try
    End Sub

    Private Sub txtUrl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUrl.Click
        If MouseButtons = Windows.Forms.MouseButtons.Left Then
            WebBrowser1.Stop()
        End If
    End Sub

    Private Sub tsbStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbStop.Click
        WebBrowser1.Stop()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        webStatus.Text = WebBrowser1.StatusText
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        WebBrowser1.ShowPrintDialog()
    End Sub

    Private Sub txtUrl_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUrl.Enter

    End Sub

    Private Sub txtUrl_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtUrl.KeyDown
        If MouseButtons = Windows.Forms.MouseButtons.Left Then
            WebBrowser1.Stop()
        End If
        If (e.KeyCode = Keys.Enter) Then
            WebBrowser1.Navigate(txtUrl.Text)
        End If
    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        Dim Open As New OpenFileDialog()
        Open.Title = "Open Local Webpage"
        Open.CheckFileExists = True
        Open.Filter = "All Files (*.*)|*.*"
        Open.ShowDialog()
        Try
            WebBrowser1.Navigate(Open.FileName)
        Catch ex As Exception
            'Do nothing on Exception
        End Try
    End Sub

    Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        WebBrowser1.ShowPrintDialog()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
        WebBrowser1.ShowPrintPreviewDialog()
    End Sub

    Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click

    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        WebBrowser1.Navigate("http://www.google.co.uk/search?hl=en&q=" & SearchBox.Text & "&btnG=Google+Search&meta=")
    End Sub

    Private Sub txtUrl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUrl.SelectedIndexChanged

    End Sub

    Private Sub PropertiesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PropertiesToolStripMenuItem.Click
        WebBrowser1.ShowPropertiesDialog()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        AboutBox1.ShowDialog()
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
        My.Computer.Clipboard.Clear()
        My.Computer.Clipboard.SetText(txtUrl.Text)
    End Sub

    Private Sub SaveWebpageAsHTMLFileToYourComputerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveWebpageAsHTMLFileToYourComputerToolStripMenuItem.Click
        WebBrowser1.ShowSaveAsDialog()
    End Sub

    Private Sub SearchBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBox.Click

    End Sub

    Private Sub SearchBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SearchBox.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            WebBrowser1.Navigate("http://www.google.co.uk/search?hl=en&q=" & SearchBox.Text & "&btnG=Google+Search&meta=")
        End If
    End Sub

    Private Sub SplitContainer1_SplitterMoved(ByVal sender As System.Object, ByVal e As System.Windows.Forms.SplitterEventArgs) Handles SplitContainer1.SplitterMoved

    End Sub

    Private Sub ClickHereToViewYourHistoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClickHereToViewYourHistoryToolStripMenuItem.Click
        History.ShowDialog()
    End Sub

    Private Sub Browser_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        My.Settings.IsFormOpen = False
        My.Settings.IsFormLoading = True
    End Sub

    Private Sub Loading(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserProgressChangedEventArgs)
        webProgress.Maximum = e.MaximumProgress
        webProgress.Value = e.CurrentProgress
        webStatus.Text = WebBrowser1.StatusText
        txtUrl.Text = WebBrowser1.Url.AbsoluteUri
        Me.Text = WebBrowser1.DocumentTitle & " - BBrowser (Tabs Enabled)"
        'Dim CurProg As Single
        'Dim MaxProg As Single
        'CurProg = e.CurrentProgress
        'MaxProg = e.MaximumProgress
        'webProgress.Value = CInt((CurProg / MaxProg) * 100)
    End Sub

    Private Sub RefreshToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshToolStripMenuItem.Click
        WebBrowser1.Refresh()
    End Sub

    Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
        WebBrowser1.Stop()
    End Sub

    Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click
        If My.Settings.UseBBrowserHomePage = "True" Then
            WebBrowser1.Navigate(My.Settings.BBrowserHomePageUrl)
        ElseIf My.Settings.UseBBrowserHomePage = "False" Then
            WebBrowser1.GoHome()
        End If
    End Sub

    Private Sub BBrowserSettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBrowserSettingsToolStripMenuItem.Click
        BBrowserSettings.ShowDialog()
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        txtUrl.Text = WebBrowser1.Url.AbsoluteUri
        Me.Text = WebBrowser1.DocumentTitle & " - BBrowser"
        With webProgress
            .Value = 0
            .Visible = False
        End With
        webStatus.Text = WebBrowser1.StatusText
        My.Settings.BrowserHistory.Add(WebBrowser1.Url.AbsoluteUri)
    End Sub

    Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
        With webProgress
            .Visible = False
            .Value = 0
        End With
    End Sub

    Private Sub WebBrowser1_NavigatingExtended(ByVal sender As Object, ByVal e As exBrowser.WebBrowserNavigatingExtendedEventArgs) Handles WebBrowser1.NavigatingExtended

        'Is it a Media File?
        Dim strFile As String
        For Each strFile In My.Settings.MediaPlayerFileTypes
            If e.Url.EndsWith(strFile) Then
                e.Cancel = True
                Dim ofrm As New BBrowserMediaPlayer
                My.Settings.MediaURL = e.Url.ToString
                ofrm.Show()
                Exit Sub
            End If
        Next
    End Sub

    Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
        'Dim CurProg As Single
        'Dim MaxProg As Single
        'CurProg = e.CurrentProgress
        'MaxProg = e.MaximumProgress
        'webProgress.Value = CInt((CurProg / MaxProg) * 100)
        With webProgress
            .Visible = True
        End With
        webProgress.Maximum = e.MaximumProgress
        If Not e.CurrentProgress = -1 Then
            webProgress.Value = e.CurrentProgress
        Else
            webProgress.Value = 0
        End If
        webStatus.Text = WebBrowser1.StatusText
        Try
            txtUrl.Text = WebBrowser1.Url.ToString
        Catch ex As Exception
        End Try
    End Sub

    Private Sub PageSetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PageSetupToolStripMenuItem.Click
        WebBrowser1.ShowPageSetupDialog()
    End Sub

    Private Sub BBrowserNewsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBrowserNewsToolStripMenuItem.Click
        BBrowserNews.Show()
    End Sub

    'Public Sub NewWindow3(ByRef pDisp As Object, ByRef cancel As Boolean, ByVal flags As Integer, _
    'ByVal URLContext As String, ByVal URL As String)

    'Dim frm As New BrowserWithoutTabs1
    'frm.Show()
    'frm.WebBrowser1.Navigate(URL)
    'cancel = True
    'End Sub

    Public Sub LoadFavourites()
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
        tvFavs.BeginUpdate()
        tvFavs.Nodes.Clear()
        'Load favourites from all sub-directories
        LoadFolders(New System.IO.DirectoryInfo(Path), Nothing)
        'Load the favourites from the favourites folder
        LoadPath(Path, Nothing)
        'Use ContextMenuStrip1 as Favourites Context Menu Strip by Bo Anderson
        tvFavs.ContextMenuStrip = ContextMenuStrip1
        'Start FileSystemWatcher
        FileSystemWatcher1.Path = Path
        FileSystemWatcher1.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.DirectoryName Or NotifyFilters.FileName
        FileSystemWatcher1.EnableRaisingEvents = True
        'Repaint
        tvFavs.EndUpdate()
    End Sub

    Public Sub LoadFolders(ByVal dirInfo As System.IO.DirectoryInfo, _
    ByVal currentNode As TreeNode)

        Dim objNode As System.Windows.Forms.TreeNode

        Dim objDir As System.IO.DirectoryInfo

        For Each objDir In dirInfo.GetDirectories()
            If currentNode Is Nothing Then
                objNode = tvFavs.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                objNode.Tag = String.Empty
            Else
                objNode = currentNode.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                objNode.Tag = String.Empty
            End If
            'Set the full path of the folder
            objNode.Tag = objDir.FullName

            If objDir.GetDirectories().Length = 0 Then
                'This Node has no further sub directories
                LoadPath(objDir.FullName, objNode)
            Else
                'Add this folder to the current node and continue processing sub-directories
                LoadFolders(objDir, objNode)
                LoadPath(objDir.FullName, objNode)
            End If
        Next objDir
    End Sub

    Public Sub LoadPath(ByVal strPath As String, _
    ByVal currentNode As TreeNode)

        Dim oNode As TreeNode
        Dim name As String
        Dim objDir As New System.IO.DirectoryInfo(strPath)
        Dim SmallIco As IntPtr
        Dim shinfo As SHFILEINFO
        shinfo = New SHFILEINFO
        'Process each file in the path with a .url extension
        Dim objFile As System.IO.FileInfo
        For Each objFile In objDir.GetFiles("*.url")
            oNode = New TreeNode
            'get the icon
            shinfo.szDislayName = New String(Chr(0), 260)
            shinfo.szTypeName = New String(Chr(0), 80)
            'Get the small icon
            SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                        Marshal.SizeOf(shinfo), _
                        SHGFI_ICON Or SHGFI_SMALLICON)
            'Set the text property to the friendly name
            name = Path.GetFileNameWithoutExtension(objFile.Name)
            Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
            tvFavs.ImageList.Images.Add(name, oIcon.ToBitmap)
            oNode.Text = name
            oNode.Tag = objFile.FullName
            oNode.ImageKey = name
            oNode.SelectedImageKey = name
            If currentNode Is Nothing Then
                tvFavs.Nodes.Add(oNode)
            Else
                currentNode.Nodes.Add(oNode)
            End If
            DestroyIcon(oIcon.Handle)
        Next objFile
    End Sub

    Private Sub OpenOrganiseFavouritesDialogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenOrganiseFavouritesDialogToolStripMenuItem.Click
        WebBrowser1.ShowOrganizeFavorites()
    End Sub

    Private Sub FileSystemWatcher1_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
        Try
            Me.Invoke(New EventHandler(AddressOf fsw_Reload))
        Catch ex As Exception
            Try
                Me.Invoke(New EventHandler(AddressOf fsw_Reload))
            Catch ex1 As Exception
                Try
                    Me.Invoke(New EventHandler(AddressOf fsw_Reload))
                Catch ex2 As Exception
                    FileSystemWatcher1.EnableRaisingEvents = False
                    LoadFavourites()
                End Try
            End Try
        End Try
    End Sub

    Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
        Try
            Me.Invoke(New EventHandler(AddressOf fsw_Reload))
        Catch ex As Exception
            Try
                Me.Invoke(New EventHandler(AddressOf fsw_Reload))
            Catch ex1 As Exception
                Try
                    Me.Invoke(New EventHandler(AddressOf fsw_Reload))
                Catch ex2 As Exception
                    FileSystemWatcher1.EnableRaisingEvents = False
                    LoadFavourites()
                End Try
            End Try
        End Try
    End Sub

    Private Sub FileSystemWatcher1_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Deleted
        Try
            Me.Invoke(New EventHandler(AddressOf fsw_Reload))
        Catch ex As Exception
            Try
                Me.Invoke(New EventHandler(AddressOf fsw_Reload))
            Catch ex1 As Exception
                Try
                    Me.Invoke(New EventHandler(AddressOf fsw_Reload))
                Catch ex2 As Exception
                    FileSystemWatcher1.EnableRaisingEvents = False
                    LoadFavourites()
                End Try
            End Try
        End Try
    End Sub

    Private Sub FileSystemWatcher1_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles FileSystemWatcher1.Renamed
        Try
            Me.Invoke(New EventHandler(AddressOf fsw_Reload))
        Catch ex As Exception
            Try
                Me.Invoke(New EventHandler(AddressOf fsw_Reload))
            Catch ex1 As Exception
                Try
                    Me.Invoke(New EventHandler(AddressOf fsw_Reload))
                Catch ex2 As Exception
                    FileSystemWatcher1.EnableRaisingEvents = False
                    LoadFavourites()
                End Try
            End Try
        End Try
    End Sub

    Private Sub fsw_Reload(ByVal source As Object, ByVal args As EventArgs)
        FileSystemWatcher1.EnableRaisingEvents = False
        LoadFavourites()
    End Sub

    Private Sub tvFavs_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvFavs.MouseMove
        ' Get a reference to the TreeView control

        Dim objTreeView As TreeView = DirectCast(sender, TreeView)

        ' Get a reference to the node under the mouse 

        ' pointer (if there is one)

        Dim objNode As TreeNode = objTreeView.GetNodeAt(e.X, e.Y)

        If objNode IsNot Nothing Then

            Dim tagtext As String = objNode.Tag

            If tagtext.EndsWith(".url") Then
                ' We're over a URL

                objTreeView.Cursor = Cursors.Hand
            Else
                ' We're over a folder

                objTreeView.Cursor = Cursors.[Default]
            End If
        Else
            ' We're over an empty region in the TreeView

            objTreeView.Cursor = Cursors.[Default]
        End If
    End Sub

    Private Sub tvFavs_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvFavs.NodeMouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            Exit Sub
        End If
        If e.Node.Nodes.Count > 0 Then
            e.Node.Expand()
        Else
            If e.Node.ImageIndex = 0 Then
                Exit Sub
            Else
                Dim obj As New tlxIni(e.Node.Tag)
                WebBrowser1.Navigate(obj.GetString("INTERNETSHORTCUT", "URL", String.Empty))
            End If
        End If
    End Sub

    Private Sub CheckForUpdatesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdatesToolStripMenuItem.Click
        If MsgBox("Would you like to check for updates? If you are using a nightly then the updater only checks if there is a new 'stable' release. This updater does not check for new nightly builds.", MsgBoxStyle.YesNo, "BBrowser Updater") = MsgBoxResult.No Then
            Exit Sub
        End If
        My.Computer.Network.DownloadFile("http://bbrowser.weebly.com/uploads/4/3/7/1/4371454/latestversionbbrowser.txt", "C:\latestversionbbrowser.txt")
        If My.Computer.FileSystem.FileExists("C:\latestversionbbrowser.txt") Then
            'Continue
        Else
            MsgBox("Could not connect to the internet to check for updates. Please check your internet connection and try again.", MsgBoxStyle.Exclamation, "Error")
            Exit Sub
        End If

        Dim isupdateavailable As String = My.Computer.FileSystem.ReadAllText("C:\latestversionbbrowser.txt")

        Label2.Visible = False
        Label2.Text = isupdateavailable
        If Not Label2.Text = "Ultimate 1.0" Then
            MsgBox("An update is available. Please close BBrowser and run BBrowser Installer to update your browser.", MsgBoxStyle.OkOnly, "Update Available")
        Else
            MsgBox("No updates are available.", MsgBoxStyle.Information, "BBrowser Updater")
            Exit Sub
        End If

        My.Computer.FileSystem.DeleteFile("C:\latestversionbbrowser.txt")
    End Sub

    Private Sub WebBrowser1_NewWindowExtended(ByVal sender As Object, _
ByVal e As exBrowser.WebBrowserNewWindowExtendedEventArgs) Handles WebBrowser1.NewWindowExtended

        e.Cancel = True
        Dim ofrm As New BrowserWithoutTabs1
        ofrm.Show()
        ofrm.WebBrowser1.Navigate(e.Url.ToString)

    End Sub

    Private Sub AddToFavouritesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToFavouritesToolStripMenuItem.Click
        AddToFav.ShowDialog()
    End Sub

    Private Sub OrganiseFavouritesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrganiseFavouritesToolStripMenuItem.Click
        WebBrowser1.ShowOrganizeFavorites()
    End Sub

#Region " Handleing Document Script Calls "
    'Since we are using the browser control, we have to handle javascript and other events raised by
    'the html document that target window.external such as add to favorites, organize favorites etc. 
    'We could implement this in the extended control itself, 
    'but for purposes of this demo, we will handle a couple common ones
    'in this region.
    '// Security note on Javascript handleing, you will probably want to check to make
    '//sure that the event was raised by a user click or show dialogs, not allow automatic running of
    '//these routines by using dialogs or other methods.
    '//Make sure your signatures match the common calls from the page.

    Public Sub AddFavorite(ByVal strURL As String, ByVal strTitle As String)
        WebBrowser1.AddToFavorites(Trim(strURL), Trim(strTitle))
    End Sub

    Public Sub OrganizeFavorites()
        WebBrowser1.ShowOrganizeFavorites()
    End Sub

    Public Sub ShowCalc()
        Process.Start("Calc.exe")
    End Sub

    Public Sub ShowSettings()
        Dim ofrm As New BBrowserSettings
        ofrm.ShowDialog(Me)
    End Sub

#End Region

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If My.Settings.TimesLoadUntilNewsReminder <= 0 Then
            Timer3.Stop()
            MsgBox("Remember to check the news section! It can contain important (and sometimes critical) information about BBrowser. It is recommended to check BBrowser News every few days.", MsgBoxStyle.OkOnly, "Reminder")
            My.Settings.TimesLoadUntilNewsReminder = 4
            Timer3.Enabled = False
        Else
            Timer3.Stop()
            Timer3.Enabled = False
        End If
    End Sub

    Private Sub ReportABugToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportABugToolStripMenuItem.Click
        Dim ofrm As New BrowserWithoutTabs1
        ofrm.Show()
        ofrm.WebBrowser1.Navigate("http://code.google.com/p/simplicity-browser/issues/entry")
    End Sub
End Class